<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>后台主页</title>
    <script src="./jquery.min.js"></script>
</head>

<body>
    <h1>首页</h1>
    <button id="btnLogout">退出登录</button>
    <script>
        $(function() {
            // 调用getInfo获取用户基本信息
            getInfo();
            $('#btnLogout').on('click', function(index) {
                // 1.清空本地存储token
                // localStorage.removeItem('token');
                // 2.重新跳转到登录页面
                location.href = './login.html';
            })
        })

        //获取用户基本信息
        function getInfo() {
            $.ajax({
                method: 'GET',
                url: '/api/username',
                // 请求头配置对象
                success: function(res) {
                    if (res.status !== 0) {
                        return alert('获取用户失败')
                    }
                },
            })
        }
    </script>
</body>

</html>